<template>
  <div class="app-container">
    <el-card>
      <el-tabs>
        <el-tab-pane label="登入账号设置">
          <!-- 放置表单 -->
          <el-form ref="userFrom" :model="fromData" :rules="rules" label-width="120px" style="margin-left: 120px; margin-top:30px">
            <el-form-item prop="username" label="姓名:">
              <el-input v-model="fromData.username" style="width:300px" />
            </el-form-item>
            <el-form-item prop="pasrwode" label="密码:">
              <el-input v-model="fromData.pasrwode" style="width:300px" type="password" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="btnOK">更新</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情"><UserInfo /></el-tab-pane>
        <el-tab-pane label="岗位信息"><JobInfo /></el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import UserInfo from './components/user-info.vue'
import JobInfo from './components/job-info.vue'
import { getUserDetailById } from '@/api/user'
import { saveUserDetailById } from '@/api/employees'
export default {
  components: {
    UserInfo,
    JobInfo
  },
  data() {
    return {
      fromData: {
        username: '',
        pasrwode: ''
      },
      rules: {
        username: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        pasrwode: [{ required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 9, message: '密码长度6-9位', trigger: 'blur' }]
      }
    }
  },
  async created() {
    this.fromData = {
      // 发送请求获取员工数据
      ...await getUserDetailById(this.$route.params.id),
      // 把密码重置为空
      passwode: ''
    }
  },
  // 更新数据
  methods: {
    async btnOK() {
      await this.$refs.userFrom.validate()
      await saveUserDetailById(this.fromData)
      this.$message.success('更新成功')
    }
  }

}
</script>

<style>

</style>
